﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HappyLearning
{
    class Person : IComparable
    {
       public int age;
       public string name;

        

        public List<Person> createPerson()
        {
            List<Person> listP = new List<Person>();
            listP.Add(new Person() { age = 30, name = "Arjun"});
            listP.Add(new Person() { age = 25, name = "Rumi" });
            listP.Add(new Person() { age = 28, name = "Anwasha" });
            return listP;
        }

        public int CompareTo(object obj)
        {
            Person newP = obj as Person;
            if (this.age > newP.age)
                return 1;
            else if (this.age == newP.age)
                return 0;
            else
                return -1;
        }

        public List<string> meetsCondition1ByLinq(string name)
        {
            List<Person> listP = this.createPerson();
            List<string> result = (from p in listP
                     where p.age > (from q in listP
                                    where q.name == name
                                    select q.age).First<int>()
                     select p.name).ToList<string>();
            return result;
        }

        public List<Person> meetsCondition1ByLamda(string name)
        {
            List<Person> listP = this.createPerson();
            listP = listP.Where(p => p.age > listP.Where(q => q.name == name).First<Person>().age).ToList<Person>();
            return listP;

        }
    }

   
}
